// Copyright (C) 2012 Ato Araki @atotto. All rights reserved.

package main

import (
	"fmt"
	"net"
	"io"
	"syscall"
)


func listner() {
	ln, err := net.Listen("tcp", ":55555")
	if err != nil {
		// TODO: error
	}
	defer ln.Close()

	for {
		// wait for lients
		conn, err := ln.Accept()
		println("wait for client ...")

		if err != nil {
			// handle error
			continue
		}
		go func() {
			
			buf := make([]byte, 1024)

			for {
				l, e := conn.Read(buf)
				switch {
				case e == nil:
					fmt.Println(string(buf[0:l]))
				case e == io.EOF:
					return
				case e != syscall.EAGAIN:
					return
				}
			}
		}()
	}
}

